using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Deepcode.Flux.Core.Systems.CMS;
using Deepcode.Flux.Core.Systems.Audit.Quick;

public partial class Public_ScheduleTasks_ExpireNodes : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		ContentManager cms = new ContentManager();
		ContentObject [] expired = cms.AdxGetExpiredNodes();
		foreach (ContentObject item in expired)
		{
			switch (item.ExpiryActionID)
			{
				case ContentExpiryMode.DELETE:
					cms.Delete( item.PK_ID );
					QuickAudit.RaiseImportant( new SystemUser(), "Flux", "CMS Expire processor", "Deleted expired node {0} ({1})", item.PK_ID, item.NodeTitle);
					break;
				case ContentExpiryMode.MOVETONODE:
					ContentObject target = cms.AdxGetByID( item.ExpiryActionDataID );
					if (target == null)
						QuickAudit.RaiseError(new SystemUser(), "Flux", "CMS Expire processor", "Could not move node ({0} ({1})) - target does not exist", item.PK_ID, item.NodeTitle);
					else
					{
						cms.MoveParent( item.PK_ID, target.PK_ID );
						item.HasEmbargoEnd = false;
						item.ExpiryActionID = ContentExpiryMode.NOTHING;
						cms.Save( item, -1 );
						QuickAudit.RaiseImportant( new SystemUser(), "Flux", "CMS Expire processor", "Moved expired item {0} ({1}) to {2} ({3})", item.PK_ID, item.NodeTitle, target.PK_ID, target.NodeTitle);
					}
					break;
			}
		}
	}
}
